package com.java.service.impl;

import com.java.dao.OrderDao;
import com.java.dao.OrderDetailDao;
import com.java.dao.impl.OrderDaoImpl;
import com.java.dao.impl.OrderDetailDaoImpl;
import com.java.domain.Order;
import com.java.domain.OrderDetail;
import com.java.service.OrderService;
import com.java.utils.DateUtils;

import java.util.List;

/**
 * @version 2020.3.4
 * @User 悠恋
 * @Data 2022/11/26
 * @Time 18:48
 */
public class OrderServiceImpl implements OrderService {
    private OrderDao orderDao = new OrderDaoImpl();
    private OrderDetailDao orderDetailDao = new OrderDetailDaoImpl();

    // 添加订单
    @Override
    public Boolean addOrder(Order order , List<OrderDetail> orderDetails) {

        int ia = orderDao.addOrder(order);
        int ib = 0;
        // 添加商品详情
        for (OrderDetail orderDetail : orderDetails) {
           ib =  orderDetailDao.addOrderDetail(orderDetail);
           if (ib < 1) return false;
        }
        return ia>0&&ib>0;
    }

    @Override
    public int updateInventory(int id, int num) {
        return orderDao.updateInventory(id, num);
    }
}
